package com.hua.controller;

import com.hua.utils.Result;
import com.hua.utils.WordDoc;
import com.hua.utils.wordUtil;
import com.hua.word.wordTemp;
import org.apache.xmlbeans.XmlException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.*;

@RestController
@RequestMapping("/api/word")
public class WordController {


//    @Resource
    @Autowired
    private wordUtil wordUtil;

    @Autowired
    private WordDoc wordDoc;

    @Autowired
    private wordTemp wordTemp;

    @PostMapping("/file")
    public Result word(MultipartFile file) {
        String path = wordUtil.Muilfile(file);
        String word = wordUtil.readWord(path);
        return Result.ok(word).message("读取成功");
    }


    @GetMapping("write")
    public Result write() throws IOException, XmlException {
        wordDoc.Write();
        return Result.ok();
    }


    @GetMapping("word")
    public Result word(){
        wordTemp.word();
        return Result.ok();
    }
}
